local kl__congjian = fk.CreateSkill {
  name = "kl__congjian",
}

local HX = require "packages.konglong.hxfs2"

kl__congjian:addEffect(fk.TargetConfirmed, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(kl__congjian.name) and data.card.type == Card.TypeTrick and not player:isNude() and
    #data.use.tos > 1
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local tos, cards = room:askToChooseCardsAndPlayers(player, {
      min_card_num = 1,
      max_card_num = 1,
      min_num = 1,
      max_num = 1,
      targets = room:getOtherPlayers(player),
      skill_name = kl__congjian.name,
      prompt = "#kl__congjian-give",
      cancelable = true,
    })
    if #tos > 0 and #cards > 0 then
      event:setCostData(self, {tos = tos, cards = cards})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cardtype = Fk:getCardById(event:getCostData(self).cards[1]).type
    room:obtainCard(event:getCostData(self).tos[1], event:getCostData(self).cards, true, fk.ReasonGive, player, kl__congjian.name)
    if not player.dead then
      if cardtype == Card.TypeBasic then
        player:drawCards(1, kl__congjian.name)
      elseif cardtype == Card.TypeEquip then
        player:drawCards(2, kl__congjian.name)
      elseif cardtype == Card.TypeTrick then
        HX.DrawCardFromPile(room, player, kl__congjian.name, 1)
      end
    end
  end,
})

return kl__congjian
